package com.XiGuaXiaoMe.controller;

import com.XiGuaXiaoMe.dao.userDao;
import com.XiGuaXiaoMe.entity.Users;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

public class findServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();

        String userName3,userName;
        userDao dao=new userDao();
         Users user=null;
        HttpSession session = req.getSession();
        //1.调用请求对象对请求体使用utf-8字符集进行重新编辑
        req.setCharacterEncoding("utf-8");
        //2.调用请求对象读取请求体参数信息
        userName3=req.getParameter("userName3");
        userName=req.getParameter("userName");
        //3.调用Dao将查询信息推送到数据库服务器上
          user=dao.find(userName3,userName);
        //4.调用响应对象，根据验证结果将不同资源文件地址写入到响应头，交给浏览器
        if(user!=null)
        {
            System.out.println("success");

            req.setAttribute("user1",user);
            req.getRequestDispatcher("/findback.jsp").forward(req,resp);

        }else{
            System.out.println("false");

            req.setAttribute("user1",user);
            req.getRequestDispatcher("/findback.jsp").forward(req,resp);
        }
    }

}
